using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for validate
/// </summary>
public class validation
{
    public validation()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    #region string
    public static bool IsDate(string value)
    {
        try
        {
            DateTime.Parse(value);
            return (true);
        }
        catch
        {
            return (false);
        }
    }
    public static bool unicode_string(string txt)
    {
        char[] c = txt.ToCharArray();
        for (int i = 0; i < c.Length; i++)
            if ((int)c[i] > 127)
                return true;
        return false;
    }
    public static bool NormalChar(char c)
    {
        if ((c <= 'z') && (c >= 'a')) return true;
        if ((c <= 'Z') && (c >= 'A')) return true;
        if ((c <= '9') && (c >= '0')) return true;
        if (c == '_') return true;
        if (c == '-') return true;
        return false;
    }
    public static bool validate_key(string key)
    {
        char[] c = key.ToCharArray();
        for (int i = 0; i < key.Length; i++)
            if (!NormalChar(c[i])) return false;
        return true;
    }
    public static string NormalizeSQL(string query)
    {
        query = query.Replace("'", "''");
        query = query.Replace("%", "[%]");
        query = query.Replace("[", "[[]");
        query = query.Replace("]", "[]]");
        return query;
    }

    //PhuongHN
    //-----------------------------------------------------------------------------
    public static string fullNamber(string Str, int len)
    {
        while (Str.Length < len)
        {
            Str = "0" + Str;
        }
        return Str;
    }
    //-----------------------------------------------------------------------------
    public static string getStrProWord(string inStr)
    {
        return getStrProWord(inStr, 60);
    }
    public static string getStrProWord(string inStr, int len)
    {
        string oStr = "";
        string w = "";
        string c = "";
        for (int i = 0; i < inStr.Length; i++)
        {
            c = inStr.Substring(i, 1);
            w = w + c;
            if (c == " " || i >= inStr.Length - 1)
            {
                oStr = oStr + getStrFix(w, len);
                w = "";
            }
        }
        return oStr;
    }
    public static string UrlToString(string str)
    {
        str = str.Replace("?", "!");
        str = str.Replace("=", "@");
        str = str.Replace("&", "$");
        return str;
    }
    public static string StringToUrl(string str)
    {
        str = str.Replace("!", "?");
        str = str.Replace("@", "=");
        str = str.Replace("$", "&");
        return str;
    }
    //-----------------------------------------------------------------------------
    public static string getStrFix(string inStr)
    {
        return getStrFix(inStr, 60);
    }
    public static string getStrFix(string inStr, int len)
    {
        string oStr = "";
        if (inStr.Length > len) oStr = inStr.Substring(0, len) + "... ";
        else oStr = inStr;
        return oStr;
    }
    #endregion
}
